package com.zisu.aradvertising.controller;

import com.google.gson.internal.$Gson$Preconditions;
import com.zisu.aradvertising.pojo.Result;
import com.zisu.aradvertising.pojo.business.VideoAndCreater;
import com.zisu.aradvertising.service.VideoAndCreaterService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/videoandcreater")
public class VideoAndCreaterController {
    @Resource
    private VideoAndCreaterService videoAndCreaterService;

    //返回单个视频和创造者信息
    @PostMapping("/findallbyvid")
    public Result<VideoAndCreater> findAllbyvidController(@RequestParam int vid){
        VideoAndCreater videoAndCreater = videoAndCreaterService.findbyvidService(vid);
        if (videoAndCreater != null) {
            return Result.success(videoAndCreater, "返回单个视频和创作者!");
        } else{
            return  Result.error("123","返回失败");
        }
    }

    //返回所有视频和创作者信息
    @PostMapping("/findall")
    public Result<List<VideoAndCreater>> findAllController(){
        List<VideoAndCreater> videoAndCreater = videoAndCreaterService.findallService();
        System.out.println(videoAndCreater);
        System.out.println("yes");

        if (videoAndCreater != null) {
            return Result.success(videoAndCreater, "返回所有视频和创作者!");
        } else{
            return  Result.error("123","返回失败");
        }
    }

    //返回单个视频创作者下的所有视频和广告位信息
    @PostMapping("/findallbycid")
    public Result<List<VideoAndCreater>> findAllbycidController(@RequestParam int cid){
        List<VideoAndCreater> videoAndCreaters = videoAndCreaterService.findallbycidService(cid);
        if (videoAndCreaters != null) {
            return Result.success(videoAndCreaters, "返回单个视频和创作者!");
        } else{
            return  Result.error("123","返回失败");
        }
    }



}
